﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PatternState
{
    /// <summary>
    /// 注意： 策略模式关注选择做不同事情    但状态模式关注同一件事不同状态的不同做法（实现）
    /// 策略模式和状态模式几乎结构一样
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        { 
            Environment environment = new Environment();
            environment.ChangeEnv(new Happy());
            environment.doSomthing();
            environment.ChangeEnv(new Angry());
            environment.doSomthing();
            environment.ChangeEnv(new Sad());
            environment.doSomthing();
            
            Console.ReadKey();
        }
         
    }

    interface IState
    {
        void doWork();

    }
     
    class Happy : IState
    {
        public void doWork()
        {
            Console.WriteLine("Happy Work");
        }
    }
    class Angry : IState
    {
        public void doWork()
        {
            Console.WriteLine("Angry Work");
        }
    }
    class Sad : IState
    {
        public void doWork()
        {
            Console.WriteLine("Sad Work");
        }
    }
     
    class Environment
    {
        IState state = null;   
        public  void ChangeEnv(IState _state)
        {
            state = _state; 
        }
        public void doSomthing()
        {
            state.doWork();
        } 
    }
     
}
